<!--{include file="header.html"}-->
  <section id="forgot_password_section" class="active">
  <!---->
      <!--{include file="nav.tpl"}-->
  <!---->
    <article id="three_container" class="active" data-scroll="true" >
    <!---->
      <div class="three_list_container">
        <ul>
          <li class="clearfix relative">
            <span class="iconfont icon iconfont_7 left">&#58909;</span>
            <input type="text" id="phone" placeholder="请输入你绑定的手机号码" class="left"/>
            <a href="javascript:void(0);" id="send" class="getcode haveback red01">获取验证码</a>
            <span id="wait" style="display: none;" class="getcode gray">59s后重新获取</span>
          </li>
          <li class="clearfix">
            <span class="iconfont icon iconfont_5 left">&#58907;</span>
              <input type="text" placeholder="请输入手机验证码" class="left" id="valicode"/>
          </li>
        </ul>
      </div>
    </article>
  </section>

<div class="instant_tip" style="display:none;"></div>

<script>
var auth = {"phone":false,"code":false};
var source = '<!--{$source}-->';
$(document).ready(function(){
    $("#phone").blur(function(){
        var phone = $(this).val();
        if(phone.length==0){
            auth.phone = false;
        }else if (!rule.phonereg.test(phone)){
            J.showToast("手机号码输入错误!");
            auth.phone = false;
        }else{
            auth.phone =  true;
        }
    });


    $("#valicode").blur(function(){
        var vcode = $(this).val();
        if(vcode.length==0){
            $(this).attr('class','error');
            auth.code = false;
        }else{
            $(this).attr('class','login_input');
            auth.code = true;
        }
    });

    $("#valicode").focus(function(){
        $(this).attr('class','login_input');
    });


    $("#send").click(function(){
      $(this).focus();
        var phone = $("#phone").val();
        if(auth.phone == false){
            J.showToast("请输入你绑定的手机号码!");
            return false;
        }
        var showTimmer;
        if (showTimmer) {
            clearTimeout(showTimmer);
        }
        $("#send").hide();
        $("#wait").show();
        $("#wait").html("获取验证码");
        
        $.ajax({
            url:'<!--{$url}-->/user/send',
            data:{phone: phone, source: source},
            async: true,
            dataType: 'json',
            type:'post',
            success:function(data){
                if(data.status){
                    $("#send").hide();
                    $("#wait").show();
                    var timeSecond = 60;
                    showTimmer = setInterval(function () {
                        $("#wait").html(timeSecond+"s&nbsp;重新获取");
                        timeSecond--;
                        if (timeSecond < 0) {
                            clearTimeout(showTimmer);
                            $("#send").show();
                            $("#wait").hide();
                            $("#wait").html("60s&nbsp;重新获取");
                        }
                    },1000);
                }else{
                    $("#login").show();
                    $("#send").show();
                    $("#wait").hide();
                    J.showToast(data.msg);
                }
            }
        });
    });

    $("#authrize").click(function(){
        var code = $("#valicode").val();
        var phone = $("#phone").val();
        if(auth.phone==false || auth.code == false){
            if(auth.phone==false){
                J.showToast("请输入你绑定的手机号码!");
                return false;
            }
            if(auth.code==false){
                J.showToast("请输入手机验证码!");
                $("#valicode").attr('class','error');
                return false;
            }
            return false;
        }
        $("#authrize").hide();
        if(source == 'bind_phone') {
          $.ajax({
            url: '<!--{$url}-->/user/bind',
            data:'code='+code+"&phone="+phone,
            async: true,
            dataType: 'json',
            type:'post',
            success:function(data){
                if(data.status){
                  window.location.href = '<!--{$url}-->/user_activity/user_info';
                }else{
                  $("#authrize").show();
                  $("#valicode").attr('class','error');
                  J.showToast(data.msg);
                }
            }
          });
        }
        else {
          $.ajax({
            url: '<!--{$url}-->/user/authrize',
            data:'code='+code+"&phone="+phone+'&source=' + source,
            async: true,
            dataType: 'json',
            type:'post',
            success:function(data){
                if(data.status){
                    window.location.href = "<!--{$url}-->/user/forgetpwd?phone="+phone
                }else{
                    $("#authrize").show();
                    $("#valicode").attr('class','error');
                    J.showToast(data.msg);
                }
            }
          });
        }
    });
 });

</script>
<!--{include file="footer.html"}-->